package com.shop.cloud.controller.startup;

import java.sql.Timestamp;
import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shop.cloud.common.mapper.JsonMapper;
import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.domain.hongfu.StartupPage;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.service.hongfu.IStartupPageService;
import com.shop.cloud.util.Page;
import com.shop.cloud.util.Response;
import com.shop.cloud.util.ResponseUtil;

@RestController
@RequestMapping(value = "startup")
public class StartUpController extends BaseController {

	private static final Logger logger=Logger.getLogger(StartUpController.class);
	
	@Autowired
	private IStartupPageService startupPageService;
	
	@RequestMapping(value = "find", method = RequestMethod.POST)
	@ResponseBody
	public Response find(@CurrentUserId Long userId,@RequestBody StartupPage startupPage){
		startupPage.setStatus(0);
		startupPage.setOrderBy("STARTUP_PAGE.create_time DESC");
		Page<StartupPage> datas=startupPageService.page(startupPage);
		return ResponseUtil.ok(datas);
	}
	
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public Response update(@CurrentUserId Long userId,@RequestBody StartupPage startupPage){
		startupPage.setStatus(1);
		startupPageService.update(startupPage);
		logger.info("启动页管理修改:"+ JsonMapper.nonDefaultMapper().toJson(startupPage));
		return ResponseUtil.ok();
	}
	
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public Response add(@CurrentUserId Long userId,@RequestBody StartupPage startupPage){
		startupPage.setStatus(0);
		startupPage.setCreateTime(new Timestamp((new Date()).getTime()));
		startupPageService.insert(startupPage);
		return ResponseUtil.ok();
	}
	
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public Response delete(@CurrentUserId Long userId,@RequestBody StartupPage startupPage){
		startupPage.setStatus(1);
		startupPageService.update(startupPage);
		logger.info("启动页管理删除:"+ JsonMapper.nonDefaultMapper().toJson(startupPage));
		return ResponseUtil.ok();
	}
	
	

}